import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types'
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '排产方案编码',
    align: "center",
    dataIndex: 'schedulingSchemeCode'
  },
  {
    title: '排产方案',
    align: "center",
    dataIndex: 'schedulingSchemeName'
  },
  //  {
  //   title: '时间格式id',
  //   align:"center",
  //   dataIndex: 'timeFormatId'
  //  },
  {
    title: '时格',
    align: "center",
    dataIndex: 'timeFormatName'
  },
  {
    title: '基础算法',
    align: "center",
    dataIndex: 'basicAlgorithm',
    customRender: ({ text }) => {
      return text == 1 ? "最短工期" : text == 2 ? '最早交货期' : text == 3 ? "按照交期与工期之间的距离" : text == 4 ? 'CR值' : ''
    },
  },
  {
    title: '结束时间',
    align: "center",
    dataIndex: 'endTime',
    customRender: ({ text }) => {
      return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
    },
  },
  {
    title: '是否已启用',
    align: "center",
    dataIndex: 'significantCondition',
    customRender: ({ text }) => {
      return text == 0 ? "否" : text == 1 ? '是' : ''
    },
  },
  {
    title: '第三方编码',
    align: "center",
    dataIndex: 'thirdPartyCode',
    ifShow: false
  },
  {
    title: '备注',
    align: "center",
    dataIndex: 'remark'
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "排产方案编码",
    field: 'businessType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "schedulingSchemeCode"
    },
    colProps: { span: 8 },
  },
  {
    label: "排产方案",
    field: 'confirmationMode',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "schedulingSchemeName"
    },
    colProps: { span: 8 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [

  {
    label: '排产方案编码',
    field: 'schedulingSchemeCode',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入排产方案编码!' }];
    },
  },
  {
    label: '排产方案',
    field: 'schedulingSchemeName',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入排产方案!' }];
    },
  },
  {
    label: '时间格式id',
    field: 'timeFormatId',
    component: 'Input',
    show: false
  },
  {
    label: '时格',
    field: 'timeFormatName',
    component: 'Input',
    slot: 'timeSlot',
  },
  {
    label: '基础算法',
    field: 'basicAlgorithm',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      options: [
        { value: 1, label: '最短工期' },
        { value: 2, label: '最早交货期' },
        { value: 3, label: '按照交期与工期之间的距离' },
        { value: 4, label: 'CR值' }
      ],
      stringToNumber: true,
    }
  },
  {
    label: '结束时间',
    field: 'endTime',
    component: 'DatePicker',
  },
  {
    label: '是否已启用',
    field: 'significantCondition',
    component: 'Select',
    defaultValue: 1,
    componentProps: {
      options: [
        { value: 0, label: '否' },
        { value: 1, label: '是' },
      ],
      stringToNumber: true,
    }
  },
  {
    label: '第三方编码',
    field: 'thirdPartyCode',
    component: 'Input',
    ifShow: false
  },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];
//子表单数据
//子表表格配置
export const psAlwaysSchedulingSchemeItemColumns: JVxeColumn[] = [

  {
    title: 'id',
    key: 'schedulingSchemeId',
    type: JVxeTypes.hidden,
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '规则名称',
    key: 'ruleName',
    type: JVxeTypes.input,
    placeholder: '请输入${title}',
    // defaultValue: 0,
    // options: [{ value: 0, label: '排产优先级' }]
  },
  // {
  //   title: '规则类别',
  //   key: 'ruleType',
  //   type: JVxeTypes.select,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: 0,
  //   options: [{ value: 0, label: '排产优先级' }]
  // },
  // {
  //   title: '序号',
  //   key: 'serialNumber',
  //   type: JVxeTypes.input,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  {
    title: '排序规则',
    key: 'ruleType',
    type: JVxeTypes.select,
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{ value: 0, label: '排产优先级' }, { value: 1, label: '分厂规则' }, { value: 2, label: '分线规则' }]
  },
  {
    title: '优先顺序',
    key: 'priority',
    type: JVxeTypes.inputNumber,
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '描述',
    key: 'descriptionType',
    type: JVxeTypes.select,
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{ value: 1, label: '按订单的交期排序' }, { value: 2, label: '按订单的数量排序' }, { value: 3, label: '按订单客户等级排序' }, { value: 4, label: '按订单的耗用产周期物料时间' }, { value: 5, label: '按工艺加工顺序排序' }]
  },
  {
    title: '状态',
    key: 'significantCondition',
    type: JVxeTypes.select,
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{ value: 0, label: '未启用' }, { value: 1, label: '已启用' }]
  },
  // {
  //   title: '第三方编码',
  //   key: 'thirdPartyCode',
  //   type: JVxeTypes.hidden,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  // {
  //   title: '备注',
  //   key: 'remark',
  //   type: JVxeTypes.input,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
]

//子表表格配置
export const psAlwaysSchedulingSchemeItemColumns2: JVxeColumn[] = [

  {
    title: 'id',
    key: 'schedulingSchemeId',
    type: JVxeTypes.hidden,
    placeholder: '请输入${title}',
    defaultValue: '',
  },

  // {
  //   title: '序号',
  //   key: 'serialNumber',
  //   type: JVxeTypes.input,
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  {
    title: '规则名称',
    key: 'ruleName',
    type: JVxeTypes.input,
    placeholder: '请输入${title}',
    // defaultValue: 1,
    // options: [{ value: 1, label: '分厂规则' }]
  },
  // {
  //   title: '规则类别',
  //   key: 'ruleType',
  //   type: JVxeTypes.select,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: 1,
  //   options: [{ value: 1, label: '分厂规则' }]
  // },
  {
    title: '排序规则',
    key: 'ruleType',
    type: JVxeTypes.select,
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{ value: 0, label: '排产优先级' }, { value: 1, label: '分厂规则' }, { value: 2, label: '分线规则' }]
  },
  {
    title: '优先顺序',
    key: 'priority',
    type: JVxeTypes.inputNumber,
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '描述',
    key: 'descriptionType',
    type: JVxeTypes.select,
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{ value: 1, label: '按订单的交期排序' }, { value: 2, label: '按订单的数量排序' }, { value: 3, label: '按订单客户等级排序' }, { value: 4, label: '按订单的耗用产周期物料时间' }, { value: 5, label: '按工艺加工顺序排序' }]
  },
  {
    title: '状态',
    key: 'significantCondition',
    type: JVxeTypes.select,
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{ value: 0, label: '未启用' }, { value: 1, label: '已启用' }]
  },
  // {
  //   title: '第三方编码',
  //   key: 'thirdPartyCode',
  //   type: JVxeTypes.hidden,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  // {
  //   title: '备注',
  //   key: 'remark',
  //   type: JVxeTypes.input,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
]

//子表表格配置
export const psAlwaysSchedulingSchemeItemColumns3: JVxeColumn[] = [

  {
    title: 'id',
    key: 'schedulingSchemeId',
    type: JVxeTypes.hidden,
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '规则名称',
    key: 'ruleName',
    type: JVxeTypes.input,
    placeholder: '请输入${title}',
    // defaultValue: 2,
    // options: [{ value: 2, label: '分线规则' }]
  },
  // {
  //   title: '规则类别',
  //   key: 'ruleType',
  //   type: JVxeTypes.select,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: 2,
  //   options: [{ value: 2, label: '分线规则' }]
  // },
  // {
  //   title: '序号',
  //   key: 'serialNumber',
  //   type: JVxeTypes.input,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  // {
  //   title: '规则',
  //   key: 'ruleName',
  //   type: JVxeTypes.input,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  {
    title: '顺序',
    key: 'priority',
    type: JVxeTypes.inputNumber,
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '描述',
    key: 'descriptionType',
    type: JVxeTypes.select,
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{ value: 1, label: '按订单的交期排序' }, { value: 2, label: '按订单的数量排序' }, { value: 3, label: '按订单客户等级排序' }, { value: 4, label: '按订单的耗用产周期物料时间' }, { value: 5, label: '按工艺加工顺序排序' }]
  },
  {
    title: '状态',
    key: 'significantCondition',
    type: JVxeTypes.select,
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{ value: 0, label: '未启用' }, { value: 1, label: '已启用' }]
  },
  // {
  //   title: '第三方编码',
  //   key: 'thirdPartyCode',
  //   type: JVxeTypes.hidden,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
  // {
  //   title: '备注',
  //   key: 'remark',
  //   type: JVxeTypes.input,
  //   width: "200px",
  //   placeholder: '请输入${title}',
  //   defaultValue: '',
  // },
]

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}